JavaScript's - class, constructor, methods
JavaScript's (OOJS)
Today's topic - javascript class, constructor, methods
What are classes?
If i say in really simple words classes are the blueprint/template for creating objects. As you wish to call them, by using classes we can make a reusable block of code which we can use anywhere in our current project or in any other project where we need the same functionality.
Classes in javaScript are built based on prototypes.
Defining classes -
Classes are basically the same as functions or you can also say they are a kind of special functions.
So basically the classes have three parts as follows:
Class creation
You can use the class keyword to create a new class followed by the class name.
Eg - Class creation.
The constructor method
So basically constructor is a special method of class. It is executed automatically when the object is created. The use of constructor is to initialize object properties.
constructor is created using the keyword constructor.
Eg - constructor method.
Class methods
Class methods are just the same as object methods. Once you create a class you can use as many methods as you want in a single class.
Eg - Class method.
Summary of today's post
Classes are the blueprints to create an object and classes can be created using the class keyword.
Constructors are used to initialize objects and constructors can be created using the constructor keyword.
Class methods are just the same as object methods. Executes the code in them when they are called.
great work !! keep going .
ReplyDelete